package com.itheima.controller.backend.security.order;


import com.itheima.common.entity.PageResult;
import com.itheima.common.entity.QueryPageBean;
import com.itheima.common.entity.Result;
import com.itheima.pojo.CheckGroup;
import com.itheima.pojo.CheckItem;
import com.itheima.service.CheckGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/checkgroup")
public class CheckGroupController {

    @Autowired
    CheckGroupService checkGroupServcice;

    @PostMapping("/add")
    public Result addCheckGroup(@RequestBody CheckGroup checkGroup,@RequestParam Integer[] checkitemIds) {

        checkGroupServcice.addCheckGroup(checkGroup,checkitemIds);

        return new Result(true, "添加成功");


    }

    @GetMapping("/deleteById")
    public Result deleteById(@RequestParam Integer id) {

        checkGroupServcice.deleteById(id);

        return new Result(true, "删除成功");


    }

    @GetMapping("/findCheckGroupIdsBySetmealId")
    public Result findCheckGroupIdsBySetmealId(@RequestParam Integer setmealId) {

        // 这里可以调用相应的服务方法来获取检查组ID列表
        // 假设有一个方法 checkGroupServcice.findCheckGroupIdsBySetmealId(setmealId)
        // 返回一个List<Integer>类型的结果

        List<Integer> ids = checkGroupServcice.findCheckGroupIdsBySetmealId(setmealId);

        return new Result(true, "查询成功", ids);
    }

    @PostMapping("/findPage")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean) {

        List<CheckGroup> checkGroupList = checkGroupServcice.findPage(queryPageBean);
        Long total = checkGroupServcice.findCount()  ;
        return new PageResult(total, checkGroupList);
    }

    @PostMapping("/edit")
    public Result editCheckGroup(@RequestBody CheckGroup checkGroup,@RequestParam Integer[] checkitemIds) {

        checkGroupServcice.editCheckGroup(checkGroup,checkitemIds);

        return new Result(true, "添加成功");


    }

    @GetMapping("/findAll")
    public Result findAll() {

        List<CheckGroup> checkGroupList = checkGroupServcice.findAll();

        return new Result(true, "查询成功", checkGroupList);
    }

    @GetMapping("/findById")
    public Result findById(@RequestParam Integer id) {

        CheckGroup checkGroup = checkGroupServcice.findById(id);

        return new Result(true, "查询成功", checkGroup);
    }

}
